package com.ax.base.drugproducer.dao;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.ax.base.common.domain.Tree;
import com.ax.base.drugproducer.domain.BaseDrugClass;
import com.ax.base.system.domain.MenuDO;

@Mapper
public interface BaseDrugClassMapper {
    int deleteByPrimaryKey(Long drugClassId);

    int insert(BaseDrugClass record);

    /**
	 * 药品分类增加(模块:药品分类)
	 * 
	 * @param BaseDrugClass baseDrugClass
	 *           
	 * @return SUCC
	 */
    @Insert("<script>"+
    "insert into base_drug_class (Drug_Class_ID, Drug_Class_Code, Drug_Class_Name,"+ 
	      "First_Letter, Parent_Class_ID, Remarks,"+ 
	      "create_date, update_date, Flag"+
	      ")"+
	      "values (#{drugClassId}, #{drugClassCode}, #{drugClassName},"+ 
	      "#{firstLetter}, #{parentClassId}, #{remarks},"+ 
	      "NOW(), NOW(), #{flag}"+
	      ")"+
    	"</script>")
    int insertSelective(BaseDrugClass record);

    /**
	 * 药品分类增加(模块:药品分类)*跳转增加页面
	 * 
	 * @param Long pId
	 *           
	 * @return BaseDrugClass baseDrugClass
	 */
    @Select("<script>"+
    		"select "+
    		"Drug_Class_ID menuId, Drug_Class_Code drugClassCode, Drug_Class_Name name, First_Letter firstLetter, Parent_Class_ID parentId, Remarks remarks,"+ 
    	    "create_date createDate, update_date updateDate, Flag flag "+
    	    "from base_drug_class"+
    	    "<where>" + 
    	  	"<if test=\"drugClassId != null\">"+ "and Drug_Class_ID = #{drugClassId} " + "</if>" + 
    	  	"</where>"+
    		"</script>")
    BaseDrugClass selectByPrimaryKey(@Param("drugClassId")Long drugClassId);

    /**
	 * 药品分类修改(模块:药品分类)
	 * 
	 * @param BaseDrugClass baseDrugClass
	 *           
	 * @return SUCC
	 */
    @Update("<script>"+
    		"update base_drug_class"+
    	    "<set>"+
    	    "<if test=\"drugClassCode != null and drugClassCode != ''\">"+ "Drug_Class_Code = #{drugClassCode}, " + "</if>" +
    	    "<if test=\"drugClassName != null and drugClassName != ''\">"+ "Drug_Class_Name = #{drugClassName}, " + "</if>" + 
    	    "<if test=\"firstLetter != null and firstLetter != ''\">"+ "First_Letter = #{firstLetter}, " + "</if>" +
    	    "<if test=\"parentClassId != null\">"+ "Parent_Class_ID = #{parentClassId}, " + "</if>" +
    	    "<if test=\"remarks != null and remarks != ''\">"+ "Remarks = #{remarks}, " + "</if>" +
    	    "<if test=\"createDate != null\">"+ "create_date = #{createDate}, " + "</if>" +
    	    "update_date = NOW(),"+
    	    "<if test=\"flag != null\">"+ "Flag = #{flag}, " + "</if>" + 
    	    "</set>"+
    	    "where Drug_Class_ID = #{drugClassId,jdbcType=BIGINT}"+
    		"</script>")
    int updateByPrimaryKeySelective(BaseDrugClass record);

    int updateByPrimaryKey(BaseDrugClass record);
    
    /**
	 * 药品分类查询(模块:药品)
	 * 
	 * @param Map<String, Object> map
	 *           
	 * @return List<BaseDrugClass>
	 */
    @Select("<script>"+
    		"select "+
    		"Drug_Class_ID menuId, Drug_Class_Code drugClassCode, Drug_Class_Name name, First_Letter firstLetter, Parent_Class_ID parentId, Remarks remarks,"+ 
    	    "create_date createDate, update_date updateDate, Flag flag,Drug_Class_Type type "+
    	    "from base_drug_class"+
    	    "<where>" + 
    	  	"<if test=\"drugClassId != null\">"+ "and Drug_Class_ID = #{drugClassId} " + "</if>" + 
    	  	"</where>"+
    		"</script>")
    List<BaseDrugClass> queryDrugclassMapper(Map<String,Object> map);
    
    /**
	 * 验证类型名称是否重复(新增)
	 * 
	 * @param String parameter
	 *         
	 * @return boolean
	 */
    @Select("<script>"+
    		"select "+
    		"Drug_Class_ID menuId, Drug_Class_Code drugClassCode, Drug_Class_Name name, First_Letter firstLetter, Parent_Class_ID parentId, Remarks remarks,"+ 
    	    "create_date createDate, update_date updateDate, Flag flag,Drug_Class_Type type "+
    	    "from base_drug_class where Drug_Class_Name = #{drugClassName} and Parent_Class_ID = #{parentClassId}"+
    		"</script>")
    List<BaseDrugClass> validateMapper(Map<String,Object> map);
    
    /**
	 * 验证类型名称是否重复(修改)
	 * 
	 * @param String parameter
	 *         
	 * @return boolean
	 */
    @Select("<script>"+
    		"select "+
    		"Drug_Class_ID menuId, Drug_Class_Code drugClassCode, Drug_Class_Name name, First_Letter firstLetter, Parent_Class_ID parentId, Remarks remarks,"+ 
    	    "create_date createDate, update_date updateDate, Flag flag,Drug_Class_Type type "+
    	    "from base_drug_class where Drug_Class_Name = #{drugClassName} and Parent_Class_ID = #{parentClassId} and Drug_Class_ID != #{drugClassId}"+
    		"</script>")
    List<BaseDrugClass> validateUpdateMapper(Map<String,Object> map);
    
    /**
	 * Tree
	 * 
	 * @param Long parentClassId
	 *           
	 * @return List<Tree<MenuDO>>
	 */
    @Select("SELECT Drug_Class_ID id,Drug_Class_Name text, Parent_Class_ID parentId FROM base_drug_class")
    List<Tree<MenuDO>> listClass();
}